package com.ymatou.iapi.trading.sellerquery2.service;

import java.util.Map;

import org.json.JSONObject;

import com.google.gson.reflect.TypeToken;
import com.ymt.base.YmatouBaseCall;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymttest.utils.EnvSetup;
/**
 * 查询订单商品对应卖家买家最近的订单是否取消订单
 *
 */
public class GetAdOrderInfoCall extends YmatouBaseCall {
	private static String opurl = "api/Order/getAdOrderInfo";

	public GetAdOrderInfoCall() {
		super(EnvSetup.getSystemUrl("sellerquery2_iapi"), opurl, "POST", "JSON");
	}
	@Override
	public void addDefHeader() {
		client.addHeader("Accept",
				"text/xml,text/javascript,text/html,application/json");
		client.addHeader("Content-Type", "application/json; charset=UTF-8");
	}

	/**
	 * 获取Code
	 * 
	 * @return
	 */
	public String getCode() {
		String Code = null;
		try {
			Code = new JSONObject(getReturnData()).getString("code");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return Code;
	}

	/**
	 * 获取BCode
	 * 
	 * @return
	 */
	public int getBCode() {
		int BCode = -1;
		try {
			BCode = new JSONObject(getReturnData()).getInt("bcode");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return BCode;
	}

	/**
	 * 获取Msg
	 * 
	 * @return
	 */
	public String getMsg() {
		String BCode = null;
		try {
			BCode = new JSONObject(getReturnData()).getString("msg");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return BCode;
	}

	/**
	 * 获取Data
	 * 
	 * @return
	 */
	public JSONObject getData() {
		JSONObject Data = null;
		try {
			Data = new JSONObject(getReturnData()).getJSONObject("data");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return Data;
	}

	/**
	 * 获取adProducts
	 * 
	 * @return
	 */
	public String getAdProducts() {
		String Data = null;
		try {
			Data = getData().getString("adProducts");
		} catch (Exception e) {
			Logger.debug("JSONObject[\"adProducts\"] not found.");
		}
		return Data;
	}

	public Map<String, String> getAdProductsResponse() {
		Map<String, String> Data = null;
		try {
			Data = (Map) FormatUtil.GSONToObject(getAdProducts(),
					new TypeToken<Map<String, String>>() {
					}.getType());

		} catch (Exception e) {
			//e.printStackTrace();

			Logger.debug("JSONObject[\"adProducts\"] not found.");
		}
		return Data;
	}
}